Another way to create a Channel
is via Channel()
.
This looks like a constructor, but Channel
is an interface, not a class.
In reality, Channel()
is simply a top-level factory function, sharing a name with the interface.
It takes a parameter indicating how send()
should work:
0
indicates thatsend()
should block until the consumer of the channel is able to receive the objectChannel.UNLIMITED
means thatsend()
always returns immediately, and the channel will buffer objects up until the limit of available memoryChannel.CONFLATED
means thatsend()
always returns immediately, but only the last object sent is buffered — all previous objects are lostAny other positive
Int
value (but less thanChannel.UNLIMITED
) means that the channel will buffer that number of elements, andsend()
might block until a consumer can receive objects if that buffer is full (Channel.BUFFERED
uses a default capacity of 64 elements)